<template>
    <div class="body">
        <!-- 分页 -->
        <div class="jz-loods get_more" v-show="isshow">
            <span class="loading" v-show="pagingText == '商品加载中...'"
                ><img src="../assets/images/loading2.gif" alt=""
            /></span>
            <span>{{ pagingText }}</span>
        </div>
    </div>
</template>

<script>
// import { axiosPost } from '../../axios';
// import { Toast } from 'vant';
export default {
    name: '',
    data() {
        return {
            isshow: false,
        };
    },
    props: ['pageInfo'],
    computed: {
        pagingText() {
            return this.pageInfo.pagingText;
        },
        pageNum() {
            return this.pageInfo.pageNum;
        },
        pageSatus() {
            return this.pageInfo.pageSatus;
        },
    },
    mounted() {
        window.addEventListener('scroll', this.handleScroll, true); // 监听（绑定）滚轮滚动事件
    },
    watch: {},
    methods: {
        // 滚动事件
        handleScroll() {
            let clientHeight =
                document.documentElement.clientHeight ||
                document.body.clientHeight;
            let offsetTop =
                document.documentElement.scrollHeight ||
                document.body.scrollHeight;
            // 设备/屏幕高度
            let scrollTop =
                window.pageYOffset ||
                document.documentElement.scrollTop ||
                document.body.scrollTop; // 滚动条偏移量
            // console.log(clientHeight + scrollTop + '-----' + offsetTop);
            if (scrollTop > 0) {
                this.isshow = true;
            } else {
                this.isshow = false;
            }
            // 滚动条到底部的条件
            if (
                clientHeight + scrollTop >= offsetTop - 10 &&
                this.pageInfo.pageSatus &&
                this.pageInfo.pagingText != '没有更多啦！'
            ) {
                this.$emit('changePageStatus', false);
                this.pageInfo.pageNum++;
                this.$emit('pageNext', this.pageInfo.pageNum);
            }
        },
    },
    destroyed() {
        window.removeEventListener('scroll', this.handleScroll, true); //  离开页面清除（移除）滚轮滚动事件
    },
};
</script>

<style lang="less" scope></style>
